#!/usr/bin/env bash
set -ex

# TODO try to use disk image instead of initrd, fails if I add any of:
#-device lsi,id=scsi0
#-device scsi-hd,drive=img-blkreplay
# Without either, super slow:
#-drive file=./buildroot/output.arm~/images/rootfs.ext2,if=scsi,id=img-direct,format=raw \
#-drive driver=blkreplay,if=none,image=img-direct,id=img-blkreplay \

cmd="\
time \
./buildroot/output.arm~/host/usr/bin/qemu-system-arm \
-M versatilepb \
-append 'root=/dev/sda nokaslr norandmaps printk.devkmsg=on printk.time=y - lkmc_eval=\"/rand_check.out;wget -S google.com;/poweroff.out;\"' \
-kernel ./buildroot/output.arm~/images/zImage \
-dtb ./buildroot/output.arm~/images/versatile-pb.dtb \
-serial stdio \
\
-initrd ./buildroot/output.arm~/images/rootfs.cpio \
\
-netdev user,id=net1 \
-device rtl8139,netdev=net1 \
-object filter-replay,id=replay,netdev=net1 \
"
echo "$cmd"
eval "$cmd -icount 'shift=7,rr=record,rrfile=replay.bin'"
eval "$cmd -icount 'shift=7,rr=replay,rrfile=replay.bin'"
